package com.zzy.jdk8.stringtokenizer;

import java.util.StringTokenizer;

import org.junit.Test;

public class StringTokenizerTest {

	@Test
	public void test1() {
		String s = new String("This is a test string");
		StringTokenizer st = new StringTokenizer(s); // 空格分割

		// 返回的就是分隔后 数量
		System.out.println("Token Total: " + st.countTokens());
		while (st.hasMoreElements()) {
			System.out.println(st.nextToken());
		}
	}

	@Test
	public void test2() {
		String str = "100|66,55:200|567,90:102|43,54";

		StringTokenizer strToke = new StringTokenizer(str, ":,|");// 默认不打印分隔符
		// StringTokenizer strToke=new StringTokenizer(str,":,|",true);//打印分隔符
		while (strToke.hasMoreTokens()) {
			System.out.println(strToke.nextToken());
		}
	}

}
